Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Presently I have a working system of scripts that uses MEncoder to cut and join video files together with a handful of other options etc. It's all automated and working and that's just dandy.
What I'm looking for now is a way to place text over the video using the scripts. This would be done in a similar way to subtitles, except the subtitles would be embedded in the video (so each frame actually includes the text as part of the actual frame itself).
Is there a software package/library that does this via the command line? or in some other way that can be easily managed with scripts?
Does this functionality already exist in MEncoder?
I'll give you a few examples of what I'm after.
Basically I have a script that reads in a handful of timecodes and a video file from a database, invokes mencoder to cut the specified clips from the source videos, then uses mencoder to join them all into a single file.
What I want to be able to do is:
a) Provide a timestamp on the video that would obviously update each second (this could all be calculated by the script)
b) Take some extra text from the database, along with the clip timecodes and overlay it onto the specific clip
None of this seems like it would be particularly hard to do, software wise, but i've been searching and searching for a software library that can do it with little luck.
Anyone have any ideas?
I'd be willing to PayPal somebody like $50 AUD if they can point me in the right direction o_0
There are a few ways you could go about doing this. For example, use ImageMagick on each frame separately. But I think you already hit on the easiest way—using subtitles.
Certain formats of subtitle files are easy to generate programatically (e.g., srt). Generally, if the subtitle and movie file are in the same directory (with the same basename), mplayer will automatically use the subtitle file and overlay the text (with some adjustable font and style parameters).
When using mencoder, on the other hand, you can use this behavior to “hardcode” the subtitles onto the resulting movie file using the “-sub” flag (although I think there were certain bugs with this usage on older builds of mencoder). Here is an example usage.
So I think the steps are to have a script or program (I would use Perl) to generate a text-based subtitle file with the text you want (using the format shown in the linked-to wiki page). Then, use mencoder to hardcode the subtitle file onto a single resultant video file.
Edit:
P.S. If you were serious about the PayPal, send me a personal message through email, and we could discuss that further.
Last edited by osor; 06-20-2008 at 08:10 PM.
Reason: postscript
Using the subtitle method, would I be able to change things like position on screen, background colours etc? I'm assuming using the subtitle method I'd be limited to just text too?
Using the subtitle method, would I be able to change things like position on screen, background colours etc? I'm assuming using the subtitle method I'd be limited to just text too?
With mencoder itself, I believe you can change things like font, color, style, etc. combined with somewhat crude vertical positioning (-subpos <0-100>).
But of course mencoder is not the only software capable of “flattening” a subtitle onto a video. If you want something more robust, take a look at spumux from the dvdauthor package. I am sure there is other software out there which has similar features.
I forgot to mention that instead of subtitles you can use mencoder’s cousin—ffmpeg, which has all sorts of plugins (called vhooks).
If you have the correct build of ffmpeg, there are two vhooks you may be interested in: drawtext and imlib2 (for plain and fancy text respectively). You can also use the ppm and watermark vhooks for overlaying images.
If you have the correct build of ffmpeg, there are two vhooks you may be interested in: drawtext and imlib2 (for plain and fancy text respectively). You can also use the ppm and watermark vhooks for overlaying images.
That looks like it's exactly what I'm after. I have ffmpeg installed on my system (Debian etch) but I'm unsure as to how to install these vhooks, or even to find out if they exist.
I tried calling ffmpeg with the -vhook option to see what happened:
Code:
$ ffmpeg -vhook 'vhook/imlib2.so'
<<ffmpeg version and usage output>>
vhook/imlib2.so: cannot open shared object file: No such file or directory
Failed to add video hook function: vhook/imlib2.so
I'm guessing I don't have the vhooks installed?
How do I install them so I can start using them? o_0
I suppose you mean for “Part B” from your OP, since the vhooks are more for an overlay than for dynamic text (the timecode requirement of “Part A” could be met solely by use of hardcoded subtitles).
Quote:
Originally Posted by mundy
I have ffmpeg installed on my system (Debian etch) but I'm unsure as to how to install these vhooks, or even to find out if they exist.
I tried calling ffmpeg with the -vhook option to see what happened:
Code:
$ ffmpeg -vhook 'vhook/imlib2.so'
<<ffmpeg version and usage output>>
vhook/imlib2.so: cannot open shared object file: No such file or directory
Failed to add video hook function: vhook/imlib2.so
I'm guessing I don't have the vhooks installed?
How do I install them so I can start using them? o_0
I am not quite sure what to say since I don’t use Debian (on my system, the the file is /usr/lib/vhook/imlib2.so). You can try “locate imlib2.so” to see if that gives up any files (if so, you can specify the full path at the command-line).
Perhaps you could try the ffmpeg package provided by debian-multimedia (whose manifest shows the so-files in the correct location). If none of this works, you could build from scratch.
locate imlib2.so returned /usr/lib/vhook/imlib2.so which obviously means it's on my system. I'm currently fiddling with it now, I'll let you know how I go.
As for the subtitle embedding with mencoder, I've put together a .srt file and used the -sub option in mencoder, but the resulting file returns with no subtitles at all. Heres the options i used:
I've tried playing around with the options handed to imlib2.so, thinking perhaps the documentation was out of date but it seems no matter what I do the same error occurs.
I searched google with the error message but so far have only been able to find some gentoo specific help.
As for the subtitle embedding with mencoder, I've put together a .srt file and used the -sub option in mencoder, but the resulting file returns with no subtitles at all. Heres the options i used:
Subtitles will not be hardcoded unless you are re-encoding the video (so you can’t expect “-ovc copy” to work). My advice is to keep all video parameters the same (you can use midentify in a script to get those parameters), and use “-oac copy” for the audio.
Even when using a different ovc, I alluded to previously encountered bugs in older builds of mplayer in which subtitle hardcoding didn’t work (see this thread). So if the problem persists when you follow 1., I suggest getting a newer build of mplayer/mencoder (perhaps from the repository linked above).
I'm also having a problem with ffmpeg and the imlib2.so vhook:
<SNIP>
I searched google with the error message but so far have only been able to find some gentoo specific help.
When I searched google with that error message, I came up with this hit.
P.S.,
You might also try the debian-multimedia repository I linked above.
Last edited by osor; 06-23-2008 at 02:58 PM.
Reason: postscript
Both MPlayer/MEncoder and FFMPEG were installed from the debian-multimedia repository in the first place. I'll do an upgrade and see if that helps the vhook problems.
I'll give the subtitles another go with your advice too and let you know how I go.
Still unable to get mencoder to embed the subtitles. I'm re-encoding the video and the path the the subs.srt file is fine but still not having any luck.
I've updated it to the latest version available, but still no luck =/
As far as the ffmpeg vhook goes, I got it to work. As the vhook only allows static text overlays, I had to get my script to generate a separate command for each second which would create a 1 second long clip for each clip.
This works... It's just not every practical to break the clips down further into 1 second clips and then join them again.
Still unable to get mencoder to embed the subtitles. I'm re-encoding the video and the path the the subs.srt file is fine but still not having any luck.
I've updated it to the latest version available, but still no luck =/
That would be version 1.0rc2? The above line works for me verbatim (on this test video, and the test srt file you provided) both on a Gentoo machine and an Ubuntu 8.04. Perhaps you should try from a testing or unstable repo. Or even compile the latest source.
Quote:
Originally Posted by mundy
As far as the ffmpeg vhook goes, I got it to work.
Well, this is good news. I agree that splitting up the file into one-second chunks is a horrible way to go.
If you still can’t get mencoder to work for you, you could always use something else for hardsubbing. Does spumux not work since you’re dealing with xvid? Another option is vlc, which can probably do hardcoding of subtitles, but I am not sure of its script-friendliness. Also, there may be a way to interface with a library like gstreamer, and write the overlay code as part of a program/script.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.